var g_ws_connection = null;

function connectToServer(server,port)
{
	var proto = server.substring(0,3);
	if (proto != "ws:") 
	{
		server = "ws:"+server;
	}
	g_ws_connection = new WebSocket(server+":"+port);
	return g_ws_connection != null;
}

function initNetWork()
{
	return true;
}

function addMessage(objId,msg)
{
	var obj = document.getElementById(objId);
	obj.innerHTML += msg;
}

function addMessageLine(objId,msg)
{
	addMessage(objId,msg+"</br>");
}

function Send(msg)
{
	if (g_ws_connection == null)
	{
		return false;
	}
	g_ws_connection.send(msg);
	return true;
}

function Init()
{
	addMessageLine("txtshow","Started...");
	try{
		connectToServer("192.168.1.195",9988);
		g_ws_connection.onopen = function(){
			addMessageLine("txtshow","Connection build!");
		}
		
		g_ws_connection.onmessage = function(msg){
			addMessageLine("txtshow",msg);
		}
		
		g_ws_connection.onclose = function(){
			addMessageLine("txtshow","Connection closed!");
		}
	}catch(exception){
		addMessageLine("txtshow","Exception: "+exception);
	}
}